using System;
using UnityEngine;

namespace Flaschengeist.Views 
{
	public class HelpView : BaseView
	{
		private Texture2D header;
		private Texture2D background;
		private Texture2D activeButton;
		private GUISkin skin;
		private int pagesCount;
		private int currentPage;
		
		public void Start()
		{
			pagesCount = 3;
			currentPage = 1;
			skin = (GUISkin)Resources.Load (Settings.GUI_SKIN_SMALL_TEXT);
			header = (Texture2D)Resources.Load("textures/gui_HelpHeader");
			background = (Texture2D)Resources.Load("textures/gui_menuBackground");
		}
		
		public void OnGUI()
		{
			if (IsActive)
			{
				GUI.skin = skin;	
				GUI.DrawTexture(new Rect(Screen.width/2 - 163, Screen.height/2 - 125, 326, 300),background);
				GUI.DrawTexture(new Rect(Screen.width/2 - 163, Screen.height/2 - 250, 326, 198),header);
				
				if (GUI.Button(new Rect(Screen.width/2 - 50, Screen.height/2 - 54, 25,25), "<", new GUIStyle()))
				{
					if(currentPage != 1)
						currentPage--;
				}
				
				if (GUI.Button(new Rect(Screen.width/2 + 43, Screen.height/2 - 54, 25,25), ">", new GUIStyle()))
				{
					if(currentPage != pagesCount)
						currentPage++;
				}
				
				GUI.Label(new Rect(Screen.width/2 - 30, Screen.height/2 - 57, 300, 250), "page " + currentPage.ToString() + " of " + pagesCount.ToString());
				
				switch(currentPage)
				{
					// PAGE 1
					case 1: 
						
						GUI.Label(new Rect(Screen.width/2 - 90, Screen.height/2 - 30, 300, 250), 
						"The aim of the game is to play\n" +
						"a given melody.\n\n" +
						"The tones are generated by\n" +
						"filling the glass.\n\n" +
						"When a glass is filled up,\n" +
						"the sound will be deeper.");
						break;
					
					// PAGE 2
					case 2: 
					
						GUI.Label(new Rect(Screen.width/2 - 90, Screen.height/2 - 30, 300, 250), 	
						"If you hold the left mouse button\n"+
						"down over a glass, it is filled with\n" +
						"liquid.\n\n" +
						"If you hold the right mouse button\n" +
						"down over a glass, it is emptied.");
						break;
					
					// PAGE 3
					case 3:
						GUI.Label(new Rect(Screen.width/2 - 90, Screen.height/2 - 30, 300, 250), 	
						"For filling the glasses you have\n" +
						"limited time and liquid.\n\n" +
						"If either is depleted, the\n" +
						"current melody is checked.\n\n" +
						"If you have made a lot of notes\n" +
						"correctly, you get to the next\n" +
						"level.");
						break;
				
					// DEFAULT
					default: break;
				
					
				}
				
				if (GUI.Button(new Rect(Screen.width/2 - Settings.GUI_BUTTON_WIDTH/2, Screen.height/2 + 120, Settings.GUI_BUTTON_WIDTH, Settings.GUI_BUTTON_HEIGHT), "back"))
					{
						Hide();
						Close();
					}
				
				
			}
			else
			{
				currentPage = 1;
			}
		}
	
		public event Action Close;
	}
}

